# Replication files for "Consumers' Rights in the Shadow of the Brand"

# Authors: Kantorowicz-Reznichenko, E., van Heudsen, A., & Kantorowicz, J. 

# Loading (installing) packages

# install.packages("cjoint")
# install.packages("cregg")
# install.packages("ggsci")
# install.packages("ggpubr")
# install.packages("ggsci")
# install.packages("GGally")
#install.packages("ggnewscale")
library(cjoint)
library(cregg)
library(ggsci)
library(ggpubr)
library(tidyverse)
library(GGally)
library(ggsci)
library(ggnewscale)

# Loading conjoint experiment data

comp_ind <- readRDS("computers.RDS")

laundry_ind <- readRDS("laundry_machines.RDS")

# AMCE computers (Figure 3 Panel A in the manuscript)

options(scipen=999)

x <- amce(comp_ind, selected ~ 
            Brand +
            Price +
            Processor +
            Storage.Capacity +
            RAM +
            Warranty +
            Conflict.Resolution +
            Liability +
            Privacy,
          id = ~Response.ID)

x$feature <- factor(x$feature, levels = c("Warranty",
                                          "Liability",
                                          "Conflict.Resolution",
                                          "Privacy",
                                          "Brand",
                                          "Price",
                                          "Processor",
                                          "Storage.Capacity",
                                          "RAM"))

amce <- ggplot(x,
               mapping = aes(x = estimate,
                             y = level,
                             xmin = lower,
                             xmax = upper)) +
  theme_bw() +
  new_scale_fill() +
  geom_rect(data = subset(x, feature %in% c("Warranty",
                                            "Liability",
                                            "Conflict.Resolution",
                                            "Privacy")), aes(xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf, fill = feature), alpha = 0.3, inherit.aes = FALSE) +
  scale_fill_manual(values = c("Warranty" = "azure3", 
                               "Liability" = "azure3",
                               "Conflict.Resolution" = "azure3",
                               "Privacy" = "azure3"), guide = "none") +
  theme(panel.background = element_blank()) +
  geom_pointrange(position = position_dodge(width = 0.5), size = 0.3) +
  theme(legend.position = "bottom",
        plot.title = element_text(hjust = 0.5, size = 10),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7)) +
  labs(x = "AMCEs", 
       y = "", 
       color = "Country",
       shape = "Country",
       title = "A. Computers") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_shape_manual(values=c(1, 4)) +
  scale_x_continuous(breaks=seq(-0.05,0.25,0.05)) +
  facet_wrap(~ feature, 
             scales = "free_y",
             ncol = 1)

amce

ggsave("figures/Figure_3_Panel_A.jpg",
       height = 10,
       width = 8,
       dpi = 500,
       scale = 0.7)

# AMCE laundry machines (Figure 3 Panel B in the manuscript)

y <- amce(laundry_ind, selected ~ 
            Brand +
            Conflict.Resolution +
            Liability +
            Privacy +
            Price +
            Depth +
            Noise +
            Warranty +
            Load.Capacity, 
          id = ~Response.ID)

y$feature <- factor(y$feature, levels = c("Warranty",
                                          "Liability",
                                          "Conflict.Resolution",
                                          "Privacy",
                                          "Brand",
                                          "Price",
                                          "Depth",
                                          "Load.Capacity",
                                          "Noise"))

amce <- ggplot(y,
               mapping = aes(x = estimate,
                             y = level,
                             xmin = lower,
                             xmax = upper)) +
  theme_bw() +
  new_scale_fill() +
  geom_rect(data = subset(x, feature %in% c("Warranty",
                                            "Liability",
                                            "Conflict.Resolution",
                                            "Privacy")), aes(xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf, fill = feature), alpha = 0.3, inherit.aes = FALSE) +
  scale_fill_manual(values = c("Warranty" = "azure3", 
                               "Liability" = "azure3",
                               "Conflict.Resolution" = "azure3",
                               "Privacy" = "azure3"), guide = "none") +
  theme(panel.background = element_blank()) +
  geom_pointrange(position = position_dodge(width = 0.5), size = 0.3) +
  theme(legend.position = "bottom",
        plot.title = element_text(hjust = 0.5, size = 10),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7)) +
  labs(x = "AMCEs", 
       y = "",
       title = "B. Laundry machines") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_shape_manual(values=c(1, 4)) +
  scale_x_continuous(breaks=seq(-0.05,0.25,0.05)) +
  facet_wrap(~ feature, 
             scales = "free_y",
             ncol = 1)

amce

ggsave("figures/Figure_3_Panel_B.jpg",
       height = 10,
       width = 8,
       dpi = 500,
       scale = 0.7)

# Table S1 in the supplementary material
write.csv(x, "amces_computers.csv")

# Table S2 in the supplementary material
write.csv(y, "amces_laundry_machines.csv")

# Interactions with brand familiarity

## Computers

### Computers and privacy

comp_priv_amce <- cj(comp_ind, selected ~ Privacy, id = ~Response.ID, estimate = "amce", by = ~Brand_Familiarity)

comp_priv_amce_diff <- cj(comp_ind, selected ~ Privacy, id = ~Response.ID, estimate = "amce_diff", by = ~Brand_Familiarity)

computer_privacy <- plot(rbind(comp_priv_amce, comp_priv_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.1, 0.1) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 10),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 6.5))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Privacy") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

computer_privacy

### Computers and liability

comp_liab_amce <- cj(comp_ind, selected ~ Liability, id = ~Response.ID, estimate = "amce", by = ~Brand_Familiarity)

comp_liab_amce_diff <- cj(comp_ind, selected ~ Liability, id = ~Response.ID, estimate = "amce_diff", by = ~Brand_Familiarity)

computer_liability <- plot(rbind(comp_liab_amce, comp_liab_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.1, 0.1) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 6.5))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Liability") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))


### Computers and dispute resolution

comp_resolut_amce <- cj(comp_ind, selected ~ Conflict.Resolution, id = ~Response.ID, estimate = "amce", by = ~Brand_Familiarity)

comp_resolut_amce_diff <- cj(comp_ind, selected ~ Conflict.Resolution, id = ~Response.ID, estimate = "amce_diff", by = ~Brand_Familiarity)

computer_conflict_resolution <- plot(rbind(comp_resolut_amce, comp_resolut_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.1, 0.1) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 6.5))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Conflict.Resolution") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

computer_conflict_resolution

### Computers and warranty

comp_warranty_amce <- cj(comp_ind, selected ~ Warranty, id = ~Response.ID, estimate = "amce", by = ~Brand_Familiarity)

comp_warranty_amce_diff <- cj(comp_ind, selected ~ Warranty, id = ~Response.ID, estimate = "amce_diff", by = ~Brand_Familiarity)

computer_warranty <- plot(rbind(comp_warranty_amce, comp_warranty_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.2, 0.2) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 6.5))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Warranty") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

computer_warranty

### Figure 4 in the manuscript (Panel A)

p_computers <- ggarrange(computer_warranty, 
                         computer_liability, 
                         computer_conflict_resolution,
                         ncol = 1, 
                         nrow = 3,
                         align = 'v')

p_computers_final <- annotate_figure(p_computers, top = text_grob("A. Computers", 
                                                                  face = "bold", 
                                                                  size = 14,
                                                                  hjust = -0.0))

ggsave("figures/Figure_4_Panel_A.jpg",
       height = 10,
       width = 10,
       dpi = 500,
       scale = 0.7)

## Laundry

### Laundry and privacy

laundry_priv_amce <- cj(laundry_ind, selected ~ Privacy, id = ~Response.ID, estimate = "amce", by = ~Brand_Familiarity)

laundry_priv_amce_diff <- cj(laundry_ind, selected ~ Privacy, id = ~Response.ID, estimate = "amce_diff", by = ~Brand_Familiarity)

laundry_privacy <- plot(rbind(laundry_priv_amce, laundry_priv_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.1, 0.1) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 6.5))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Privacy") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

laundry_privacy

### Laundry and liability

laundry_liab_amce <- cj(laundry_ind, selected ~ Liability, id = ~Response.ID, estimate = "amce", by = ~Brand_Familiarity)

laundry_liab_amce_diff <- cj(laundry_ind, selected ~ Liability, id = ~Response.ID, estimate = "amce_diff", by = ~Brand_Familiarity)

laundry_liability <- plot(rbind(laundry_liab_amce, laundry_liab_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.1, 0.1) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 6.5))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Liability") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

laundry_liability

### Laundry and dispute resolution

laundry_resolut_amce <- cj(laundry_ind, selected ~ Conflict.Resolution, id = ~Response.ID, estimate = "amce", by = ~Brand_Familiarity)

laundry_resolut_amce_diff <- cj(laundry_ind, selected ~ Conflict.Resolution, id = ~Response.ID, estimate = "amce_diff", by = ~Brand_Familiarity)

laundry_conflict_resolution <- plot(rbind(laundry_resolut_amce, laundry_resolut_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.1, 0.1) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 6.5))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Conflict.Resolution") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

laundry_conflict_resolution

### Laundry and warranty

laundry_warrant_amce <- cj(laundry_ind, selected ~ Warranty, id = ~Response.ID, estimate = "amce", by = ~Brand_Familiarity)

laundry_warrant_amce_diff <- cj(laundry_ind, selected ~ Warranty, id = ~Response.ID, estimate = "amce_diff", by = ~Brand_Familiarity)

laundry_warranty <- plot(rbind(laundry_warrant_amce, laundry_warrant_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.2, 0.2) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 6.5))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Warranty") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

laundry_warranty

### Figure 4 in the manuscript (Panel B)

p_laundry <- ggarrange(laundry_warranty, 
                       laundry_liability, 
                       laundry_conflict_resolution,
                       ncol = 1, 
                       nrow = 3,
                       align = 'v')

p_laundry_final <- annotate_figure(p_laundry, top = text_grob("B. Laundry machines", 
                                                              face = "bold", 
                                                              size = 14,
                                                              hjust = 0.1))

ggsave("figures/Figure_4_Panel_B.jpg",
       height = 10,
       width = 10,
       dpi = 500,
       scale = 0.7)

### Figure 4 in the manuscript (Panel A and Panel B jointly)

ggarrange(p_computers_final, p_laundry_final,
          ncol = 2, 
          nrow = 1,
          align = "hv")

ggsave("figures/Figure_4.jpg",
       height = 8,
       width = 15,
       dpi = 500,
       scale = 0.7)

### Figure 5 in the manuscript

p_computers_privacy_final <- annotate_figure(computer_privacy, top = text_grob("A. Computers", 
                                                                               face = "bold", 
                                                                               size = 14,
                                                                               hjust = 0.1))

p_laundry_privacy_final <- annotate_figure(laundry_privacy, top = text_grob("B. Laundry machines", 
                                                                            face = "bold", 
                                                                            size = 14,
                                                                            hjust = 0.1))

ggarrange(p_computers_privacy_final, p_laundry_privacy_final,
          ncol = 2, 
          nrow = 1,
          align = "hv")

ggsave("figures/Figure_5.jpg",
       height = 4,
       width = 15,
       dpi = 500,
       scale = 0.7)

# Interactions with brand familiarity

## Computers

### Computers and Price 

comp_ind <- comp_ind %>% mutate(Price_dummy = ifelse(Price=="$500", "Low",
                                             ifelse(Price=="$1250" | Brand=="$2000", "High", NA)))

comp_ind$Price_dummy <- factor(comp_ind$Price_dummy,
                           levels = c("High",
                                      "Low"))

### Computers and privacy

comp_priv_amce <- cj(comp_ind, selected ~ Privacy, id = ~Response.ID, estimate = "amce", by = ~Price_dummy)

comp_priv_amce_diff <- cj(comp_ind, selected ~ Privacy, id = ~Response.ID, estimate = "amce_diff", by = ~Price_dummy)

computers_price_privacy <- plot(rbind(comp_priv_amce, comp_priv_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.1, 0.1) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 10))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Privacy") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

computers_price_privacy

### Computers and liability

comp_liab_amce <- cj(comp_ind, selected ~ Liability, id = ~Response.ID, estimate = "amce", by = ~Price_dummy)

comp_liab_amce_diff <- cj(comp_ind, selected ~ Liability, id = ~Response.ID, estimate = "amce_diff", by = ~Price_dummy)

computers_price_liability <- plot(rbind(comp_liab_amce, comp_liab_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.1, 0.1) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 10))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Liability") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

computers_price_liability

### Computers and dispute resolution

comp_resolut_amce <- cj(comp_ind, selected ~ Conflict.Resolution, id = ~Response.ID, estimate = "amce", by = ~Price_dummy)

comp_resolut_amce_diff <- cj(comp_ind, selected ~ Conflict.Resolution, id = ~Response.ID, estimate = "amce_diff", by = ~Price_dummy)

computers_price_conflict_resolution <- plot(rbind(comp_resolut_amce, comp_resolut_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.1, 0.1) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 10))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Conflict.Resolution") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

computers_price_conflict_resolution

### Computers and warranty

comp_warranty_amce <- cj(comp_ind, selected ~ Warranty, id = ~Response.ID, estimate = "amce", by = ~Price_dummy)

comp_warranty_amce_diff <- cj(comp_ind, selected ~ Warranty, id = ~Response.ID, estimate = "amce_diff", by = ~Price_dummy)

computers_price_warranty <- plot(rbind(comp_warranty_amce, comp_warranty_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.25, 0.25) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 10))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Warranty") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

computers_price_warranty

## Laundry

### Laundry and price

laundry_ind <- laundry_ind %>% mutate(Price_dummy = ifelse(Price=="$400", "Low",
                                                   ifelse(Price=="$900" | Brand=="$1400", "High", NA)))

laundry_ind$Price_dummy <- factor(laundry_ind$Price_dummy,
                              levels = c("High",
                                         "Low"))

### Laundry and privacy

laundry_priv_amce <- cj(laundry_ind, selected ~ Privacy, id = ~Response.ID, estimate = "amce", by = ~Price_dummy)

laundry_priv_amce_diff <- cj(laundry_ind, selected ~ Privacy, id = ~Response.ID, estimate = "amce_diff", by = ~Price_dummy)

laundry_price_privacy <- plot(rbind(laundry_priv_amce, laundry_priv_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.1, 0.1) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 10))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Privacy") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

laundry_price_privacy

### Laundry and liability

laundry_liab_amce <- cj(laundry_ind, selected ~ Liability, id = ~Response.ID, estimate = "amce", by = ~Price_dummy)

laundry_liab_amce_diff <- cj(laundry_ind, selected ~ Liability, id = ~Response.ID, estimate = "amce_diff", by = ~Price_dummy)

laundry_price_liability <- plot(rbind(laundry_liab_amce, laundry_liab_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.1, 0.1) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 10))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Liability") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

laundry_price_liability

### Laundry and dispute resolution

laundry_resolut_amce <- cj(laundry_ind, selected ~ Conflict.Resolution, id = ~Response.ID, estimate = "amce", by = ~Price_dummy)

laundry_resolut_amce_diff <- cj(laundry_ind, selected ~ Conflict.Resolution, id = ~Response.ID, estimate = "amce_diff", by = ~Price_dummy)

laundry_price_conflict_resolution <- plot(rbind(laundry_resolut_amce, laundry_resolut_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.1, 0.1) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 10))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Conflict.Resolution") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

laundry_price_conflict_resolution

### Laundry and warranty

laundry_warranty_amce <- cj(laundry_ind, selected ~ Warranty, id = ~Response.ID, estimate = "amce", by = ~Price_dummy)

laundry_warranty_amce_diff <- cj(laundry_ind, selected ~ Warranty, id = ~Response.ID, estimate = "amce_diff", by = ~Price_dummy)

laundry_price_warranty <- plot(rbind(laundry_warranty_amce, laundry_warranty_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.28, 0.28) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 10))+
  labs(x = "AMCEs", 
       y = "", 
       title = "Warranty") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9))

laundry_price_warranty

### Figure 6 in the manuscript (both Panel A and Panel B jointly)

p_computers_price <- ggarrange(computers_price_warranty, 
                               computers_price_liability, 
                               computers_price_warranty,
                               computers_price_privacy,
                               ncol = 1, 
                               nrow = 4,
                               align = 'v')

p_computers_price_final <- annotate_figure(p_computers_price, top = text_grob("A. Computers", 
                                                                              face = "bold", 
                                                                              size = 14,
                                                                              hjust = 0.1))

p_laundry_price <- ggarrange(laundry_price_warranty, 
                             laundry_price_liability, 
                             laundry_price_conflict_resolution,
                             laundry_price_privacy,
                             ncol = 1, 
                             nrow = 4,
                             align = 'v')

p_laundry_price_final <- annotate_figure(p_laundry_price, top = text_grob("B. Laundry machines", 
                                                                          face = "bold", 
                                                                          size = 14,
                                                                          hjust = 0.1))

ggarrange(p_computers_price_final, p_laundry_price_final,
          ncol = 2, 
          nrow = 1,
          align = "hv")

ggsave("figures/Figure_6.jpg",
       height = 10,
       width = 15,
       dpi = 500,
       scale = 0.7)

# Subgroup analysis

## Age

### Age group analysis: computers

comp_age_amce <- cj(comp_ind, selected ~ 
                      Brand +
                      Conflict.Resolution +
                      Liability +
                      Privacy +
                      Price +
                      Processor +
                      Storage.Capacity +
                      Warranty +
                      RAM, 
                    id = ~Response.ID, 
                    estimate = "amce", 
                    by = ~age_dummy)

comp_age_amce_diff <- cj(comp_ind, selected ~ 
                           Brand +
                           Conflict.Resolution +
                           Liability +
                           Privacy +
                           Price +
                           Processor +
                           Storage.Capacity +
                           Warranty +
                           RAM, 
                         id = ~Response.ID, 
                         estimate = "amce_diff", 
                         by = ~age_dummy)

comp_age_amce$feature <- factor(comp_age_amce$feature, levels = c("Warranty",
                                                                  "Liability",
                                                                  "Conflict.Resolution",
                                                                  "Privacy",
                                                                  "Brand",
                                                                  "Price",
                                                                  "Processor",
                                                                  "Storage.Capacity",
                                                                  "RAM"))

comp_age_amce <- comp_age_amce %>% filter(feature=="Warranty" |
                                            feature=="Liability" |
                                            feature=="Conflict.Resolution" |
                                            feature=="Privacy")

comp_age_amce_diff$feature <- factor(comp_age_amce_diff$feature, levels = c("Warranty",
                                                                            "Liability",
                                                                            "Conflict.Resolution",
                                                                            "Privacy",
                                                                            "Brand",
                                                                            "Price",
                                                                            "Processor",
                                                                            "Storage.Capacity",
                                                                            "RAM"))

comp_age_amce_diff <- comp_age_amce_diff %>% filter(feature=="Warranty" |
                                                      feature=="Liability" |
                                                      feature=="Conflict.Resolution" |
                                                      feature=="Privacy")

comp_age <- plot(rbind(comp_age_amce, comp_age_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.25, 0.25) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 9))+
  labs(x = "AMCEs", 
       y = "", 
       title = "A. Computers") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9)) +
  facet_grid(feature ~ BY, 
             scales = "free")

comp_age

#### Figure S7 in the supplementary material

ggsave("figures/Figure_S7.jpg",
       height = 8,
       width = 12,
       dpi = 500,
       scale = 0.7)

### Age group analysis: laundry machines

laundry_age_amce <- cj(laundry_ind, selected ~ 
                         Brand +
                         Conflict.Resolution +
                         Liability +
                         Privacy +
                         Price +
                         Depth +
                         Noise +
                         Warranty +
                         Load.Capacity, 
                       id = ~Response.ID, 
                       estimate = "amce", 
                       by = ~age_dummy)

laundry_age_amce_diff <- cj(laundry_ind, selected ~ 
                              Brand +
                              Conflict.Resolution +
                              Liability +
                              Privacy +
                              Price +
                              Depth +
                              Noise +
                              Warranty +
                              Load.Capacity, 
                            id = ~Response.ID, 
                            estimate = "amce_diff", 
                            by = ~age_dummy)

laundry_age_amce$feature <- factor(laundry_age_amce$feature, levels = c("Warranty",
                                                                        "Liability",
                                                                        "Conflict.Resolution",
                                                                        "Privacy",
                                                                        "Brand",
                                                                        "Price",
                                                                        "Depth",
                                                                        "Load.Capacity",
                                                                        "Noise"))

laundry_age_amce <- laundry_age_amce %>% filter(feature=="Warranty" |
                                                  feature=="Liability" |
                                                  feature=="Conflict.Resolution" |
                                                  feature=="Privacy")

laundry_age_amce_diff$feature <- factor(laundry_age_amce_diff$feature, levels = c("Warranty",
                                                                                  "Liability",
                                                                                  "Conflict.Resolution",
                                                                                  "Privacy",
                                                                                  "Brand",
                                                                                  "Price",
                                                                                  "Depth",
                                                                                  "Load.Capacity",
                                                                                  "Noise"))

laundry_age_amce_diff <- laundry_age_amce_diff %>% filter(feature=="Warranty" |
                                                            feature=="Liability" |
                                                            feature=="Conflict.Resolution" |
                                                            feature=="Privacy")

laundry_age <- plot(rbind(laundry_age_amce, laundry_age_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.30, 0.30) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 9))+
  labs(x = "AMCEs", 
       y = "", 
       title = "B. Laundry machines") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9)) +
  facet_grid(feature ~ BY, 
             scales = "free")

laundry_age

#### Figure S8 in the supplementary material

ggsave("figures/Figure_S8.jpg",
       height = 8,
       width = 12,
       dpi = 500,
       scale = 0.7)

## Gender

### Gender group analysis: computers

comp_gender_amce <- cj(comp_ind, selected ~ 
                         Brand +
                         Conflict.Resolution +
                         Liability +
                         Privacy +
                         Price +
                         Processor +
                         Storage.Capacity +
                         Warranty +
                         RAM, 
                       id = ~Response.ID, 
                       estimate = "amce", 
                       by = ~gender_dummy)

comp_gender_amce_diff <- cj(comp_ind, selected ~ 
                              Brand +
                              Conflict.Resolution +
                              Liability +
                              Privacy +
                              Price +
                              Processor +
                              Storage.Capacity +
                              Warranty +
                              RAM, 
                            id = ~Response.ID, 
                            estimate = "amce_diff", 
                            by = ~gender_dummy)

comp_gender_amce$feature <- factor(comp_gender_amce$feature, levels = c("Warranty",
                                                                        "Liability",
                                                                        "Conflict.Resolution",
                                                                        "Privacy",
                                                                        "Brand",
                                                                        "Price",
                                                                        "Processor",
                                                                        "Storage.Capacity",
                                                                        "RAM"))

comp_gender_amce <- comp_gender_amce %>% filter(feature=="Warranty" |
                                                  feature=="Liability" |
                                                  feature=="Conflict.Resolution" |
                                                  feature=="Privacy")

comp_gender_amce_diff$feature <- factor(comp_gender_amce_diff$feature, levels = c("Warranty",
                                                                                  "Liability",
                                                                                  "Conflict.Resolution",
                                                                                  "Privacy",
                                                                                  "Brand",
                                                                                  "Price",
                                                                                  "Processor",
                                                                                  "Storage.Capacity",
                                                                                  "RAM"))

comp_gender_amce_diff <- comp_gender_amce_diff %>% filter(feature=="Warranty" |
                                                            feature=="Liability" |
                                                            feature=="Conflict.Resolution" |
                                                            feature=="Privacy")

comp_gender <- plot(rbind(comp_gender_amce, comp_gender_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.25, 0.25) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 9))+
  labs(x = "AMCEs", 
       y = "", 
       title = "A. Computers") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9)) +
  facet_grid(feature ~ BY, 
             scales = "free")

comp_gender

#### Figure S9 in the supplementary material

ggsave("figures/Figure_S9.jpg",
       height = 8,
       width = 12,
       dpi = 500,
       scale = 0.7)

### Gender group analysis: laundry machines

laundry_gender_amce <- cj(laundry_ind, selected ~ 
                            Brand +
                            Conflict.Resolution +
                            Liability +
                            Privacy +
                            Price +
                            Depth +
                            Noise +
                            Warranty +
                            Load.Capacity, 
                          id = ~Response.ID, 
                          estimate = "amce", 
                          by = ~gender_dummy)

laundry_gender_amce_diff <- cj(laundry_ind, selected ~ 
                                 Brand +
                                 Conflict.Resolution +
                                 Liability +
                                 Privacy +
                                 Price +
                                 Depth +
                                 Noise +
                                 Warranty +
                                 Load.Capacity, 
                               id = ~Response.ID, 
                               estimate = "amce_diff", 
                               by = ~gender_dummy)

laundry_gender_amce$feature <- factor(laundry_gender_amce$feature, levels = c("Warranty",
                                                                              "Liability",
                                                                              "Conflict.Resolution",
                                                                              "Privacy",
                                                                              "Brand",
                                                                              "Price",
                                                                              "Depth",
                                                                              "Load.Capacity",
                                                                              "Noise"))

laundry_gender_amce <- laundry_gender_amce %>% filter(feature=="Warranty" |
                                                        feature=="Liability" |
                                                        feature=="Conflict.Resolution" |
                                                        feature=="Privacy")

laundry_gender_amce_diff$feature <- factor(laundry_gender_amce_diff$feature, levels = c("Warranty",
                                                                                        "Liability",
                                                                                        "Conflict.Resolution",
                                                                                        "Privacy",
                                                                                        "Brand",
                                                                                        "Price",
                                                                                        "Depth",
                                                                                        "Load.Capacity",
                                                                                        "Noise"))

laundry_gender_amce_diff <- laundry_gender_amce_diff %>% filter(feature=="Warranty" |
                                                                  feature=="Liability" |
                                                                  feature=="Conflict.Resolution" |
                                                                  feature=="Privacy")

laundry_gender <- plot(rbind(laundry_gender_amce, laundry_gender_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.30, 0.30) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 9))+
  labs(x = "AMCEs", 
       y = "", 
       title = "B. Laundry machines") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9)) +
  facet_grid(feature ~ BY, 
             scales = "free")

laundry_gender

#### Figure S10 in the supplementary material

ggsave("figures/Figure_S10.jpg",
       height = 8,
       width = 12,
       dpi = 500,
       scale = 0.7)

## Education

### Higher education group analysis: computers

comp_education_amce <- cj(comp_ind, selected ~ 
                            Brand +
                            Conflict.Resolution +
                            Liability +
                            Privacy +
                            Price +
                            Processor +
                            Storage.Capacity +
                            Warranty +
                            RAM, 
                          id = ~Response.ID, 
                          estimate = "amce", 
                          by = ~education_dummy)

comp_education_amce_diff <- cj(comp_ind, selected ~ 
                                 Brand +
                                 Conflict.Resolution +
                                 Liability +
                                 Privacy +
                                 Price +
                                 Processor +
                                 Storage.Capacity +
                                 Warranty +
                                 RAM, 
                               id = ~Response.ID, 
                               estimate = "amce_diff", 
                               by = ~education_dummy)

comp_education_amce$feature <- factor(comp_education_amce$feature, levels = c("Warranty",
                                                                              "Liability",
                                                                              "Conflict.Resolution",
                                                                              "Privacy",
                                                                              "Brand",
                                                                              "Price",
                                                                              "Processor",
                                                                              "Storage.Capacity",
                                                                              "RAM"))

comp_education_amce <- comp_education_amce %>% filter(feature=="Warranty" |
                                                        feature=="Liability" |
                                                        feature=="Conflict.Resolution" |
                                                        feature=="Privacy")

comp_education_amce_diff$feature <- factor(comp_education_amce_diff$feature, levels = c("Warranty",
                                                                                        "Liability",
                                                                                        "Conflict.Resolution",
                                                                                        "Privacy",
                                                                                        "Brand",
                                                                                        "Price",
                                                                                        "Processor",
                                                                                        "Storage.Capacity",
                                                                                        "RAM"))

comp_education_amce_diff <- comp_education_amce_diff %>% filter(feature=="Warranty" |
                                                                  feature=="Liability" |
                                                                  feature=="Conflict.Resolution" |
                                                                  feature=="Privacy")

comp_education <- plot(rbind(comp_education_amce, comp_education_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.25, 0.25) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 8))+
  labs(x = "AMCEs", 
       y = "", 
       title = "A. Computers") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9)) +
  facet_grid(feature ~ BY, 
             scales = "free")

comp_education

#### Figure S5 in the supplementary material

ggsave("figures/Figure_S5.jpg",
       height = 8,
       width = 12,
       dpi = 500,
       scale = 0.7)

### Higher education group analysis: laundry machines

laundry_education_amce <- cj(laundry_ind, selected ~ 
                               Brand +
                               Conflict.Resolution +
                               Liability +
                               Privacy +
                               Price +
                               Depth +
                               Noise +
                               Warranty +
                               Load.Capacity, 
                             id = ~Response.ID, 
                             estimate = "amce", 
                             by = ~education_dummy)

laundry_education_amce_diff <- cj(laundry_ind, selected ~ 
                                    Brand +
                                    Conflict.Resolution +
                                    Liability +
                                    Privacy +
                                    Price +
                                    Depth +
                                    Noise +
                                    Warranty +
                                    Load.Capacity, 
                                  id = ~Response.ID, 
                                  estimate = "amce_diff", 
                                  by = ~education_dummy)

laundry_education_amce$feature <- factor(laundry_education_amce$feature, levels = c("Warranty",
                                                                                    "Liability",
                                                                                    "Conflict.Resolution",
                                                                                    "Privacy",
                                                                                    "Brand",
                                                                                    "Price",
                                                                                    "Depth",
                                                                                    "Load.Capacity",
                                                                                    "Noise"))

laundry_education_amce <- laundry_education_amce %>% filter(feature=="Warranty" |
                                                              feature=="Liability" |
                                                              feature=="Conflict.Resolution" |
                                                              feature=="Privacy")

laundry_education_amce_diff$feature <- factor(laundry_education_amce_diff$feature, levels = c("Warranty",
                                                                                              "Liability",
                                                                                              "Conflict.Resolution",
                                                                                              "Privacy",
                                                                                              "Brand",
                                                                                              "Price",
                                                                                              "Depth",
                                                                                              "Load.Capacity",
                                                                                              "Noise"))

laundry_education_amce_diff <- laundry_education_amce_diff %>% filter(feature=="Warranty" |
                                                                        feature=="Liability" |
                                                                        feature=="Conflict.Resolution" |
                                                                        feature=="Privacy")

laundry_education <- plot(rbind(laundry_education_amce, laundry_education_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.30, 0.30) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 8))+
  labs(x = "AMCEs", 
       y = "", 
       title = "B. Laundry machines") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9)) +
  facet_grid(feature ~ BY, 
             scales = "free")

laundry_education

#### Figure S6 in the supplementary material

ggsave("figures/Figure_S6.jpg",
       height = 8,
       width = 12,
       dpi = 500,
       scale = 0.7)

## Income

### Income group analysis: computers

comp_income_amce <- cj(comp_ind, selected ~ 
                         Brand +
                         Conflict.Resolution +
                         Liability +
                         Privacy +
                         Price +
                         Processor +
                         Storage.Capacity +
                         Warranty +
                         RAM, 
                       id = ~Response.ID, 
                       estimate = "amce", 
                       by = ~income_dummy)

comp_income_amce_diff <- cj(comp_ind, selected ~ 
                              Brand +
                              Conflict.Resolution +
                              Liability +
                              Privacy +
                              Price +
                              Processor +
                              Storage.Capacity +
                              Warranty +
                              RAM, 
                            id = ~Response.ID, 
                            estimate = "amce_diff", 
                            by = ~income_dummy)

comp_income_amce$feature <- factor(comp_income_amce$feature, levels = c("Warranty",
                                                                        "Liability",
                                                                        "Conflict.Resolution",
                                                                        "Privacy",
                                                                        "Brand",
                                                                        "Price",
                                                                        "Processor",
                                                                        "Storage.Capacity",
                                                                        "RAM"))

comp_income_amce <- comp_income_amce %>% filter(feature=="Warranty" |
                                                  feature=="Liability" |
                                                  feature=="Conflict.Resolution" |
                                                  feature=="Privacy")

comp_income_amce_diff$feature <- factor(comp_income_amce_diff$feature, levels = c("Warranty",
                                                                                  "Liability",
                                                                                  "Conflict.Resolution",
                                                                                  "Privacy",
                                                                                  "Brand",
                                                                                  "Price",
                                                                                  "Processor",
                                                                                  "Storage.Capacity",
                                                                                  "RAM"))

comp_income_amce_diff <- comp_income_amce_diff %>% filter(feature=="Warranty" |
                                                            feature=="Liability" |
                                                            feature=="Conflict.Resolution" |
                                                            feature=="Privacy")

comp_income <- plot(rbind(comp_income_amce, comp_income_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.25, 0.25) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 8))+
  labs(x = "AMCEs", 
       y = "", 
       title = "A. Computers") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9)) +
  facet_grid(feature ~ BY, 
             scales = "free")

comp_income

#### Figure S3 in the supplementary material

ggsave("figures/Figure_S3.jpg",
       height = 8,
       width = 12,
       dpi = 500,
       scale = 0.7)

# Income group analysis: laundry machines

laundry_income_amce <- cj(laundry_ind, selected ~ 
                            Brand +
                            Conflict.Resolution +
                            Liability +
                            Privacy +
                            Price +
                            Depth +
                            Noise +
                            Warranty +
                            Load.Capacity, 
                          id = ~Response.ID, 
                          estimate = "amce", 
                          by = ~income_dummy)

laundry_income_amce_diff <- cj(laundry_ind, selected ~ 
                                 Brand +
                                 Conflict.Resolution +
                                 Liability +
                                 Privacy +
                                 Price +
                                 Depth +
                                 Noise +
                                 Warranty +
                                 Load.Capacity, 
                               id = ~Response.ID, 
                               estimate = "amce_diff", 
                               by = ~income_dummy)

laundry_income_amce$feature <- factor(laundry_income_amce$feature, levels = c("Warranty",
                                                                              "Liability",
                                                                              "Conflict.Resolution",
                                                                              "Privacy",
                                                                              "Brand",
                                                                              "Price",
                                                                              "Depth",
                                                                              "Load.Capacity",
                                                                              "Noise"))

laundry_income_amce <- laundry_income_amce %>% filter(feature=="Warranty" |
                                                        feature=="Liability" |
                                                        feature=="Conflict.Resolution" |
                                                        feature=="Privacy")

laundry_income_amce_diff$feature <- factor(laundry_income_amce_diff$feature, levels = c("Warranty",
                                                                                        "Liability",
                                                                                        "Conflict.Resolution",
                                                                                        "Privacy",
                                                                                        "Brand",
                                                                                        "Price",
                                                                                        "Depth",
                                                                                        "Load.Capacity",
                                                                                        "Noise"))

laundry_income_amce_diff <- laundry_income_amce_diff %>% filter(feature=="Warranty" |
                                                                  feature=="Liability" |
                                                                  feature=="Conflict.Resolution" |
                                                                  feature=="Privacy")

laundry_income <- plot(rbind(laundry_income_amce, laundry_income_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.30, 0.30) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 8))+
  labs(x = "AMCEs", 
       y = "", 
       title = "B. Laundry machines") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9)) +
  facet_grid(feature ~ BY, 
             scales = "free")

laundry_income

#### Figure S4 in the supplementary material

ggsave("figures/Figure_S4.jpg",
       height = 8,
       width = 12,
       dpi = 500,
       scale = 0.7)

## Cognitive test

### Analytical thinking: computers

comp_analytical_amce <- cj(comp_ind, selected ~ 
                             Brand +
                             Conflict.Resolution +
                             Liability +
                             Privacy +
                             Price +
                             Processor +
                             Storage.Capacity +
                             Warranty +
                             RAM, 
                           id = ~Response.ID, 
                           estimate = "amce", 
                           by = ~analytical_thinking_dummy)

comp_analytical_amce_diff <- cj(comp_ind, selected ~ 
                                  Brand +
                                  Conflict.Resolution +
                                  Liability +
                                  Privacy +
                                  Price +
                                  Processor +
                                  Storage.Capacity +
                                  Warranty +
                                  RAM, 
                                id = ~Response.ID, 
                                estimate = "amce_diff", 
                                by = ~analytical_thinking_dummy)

comp_analytical_amce$feature <- factor(comp_analytical_amce$feature, levels = c("Warranty",
                                                                                "Liability",
                                                                                "Conflict.Resolution",
                                                                                "Privacy",
                                                                                "Brand",
                                                                                "Price",
                                                                                "Processor",
                                                                                "Storage.Capacity",
                                                                                "RAM"))

comp_analytical_amce <- comp_analytical_amce %>% filter(feature=="Warranty" |
                                                          feature=="Liability" |
                                                          feature=="Conflict.Resolution" |
                                                          feature=="Privacy")

comp_analytical_amce_diff$feature <- factor(comp_analytical_amce_diff$feature, levels = c("Warranty",
                                                                                          "Liability",
                                                                                          "Conflict.Resolution",
                                                                                          "Privacy",
                                                                                          "Brand",
                                                                                          "Price",
                                                                                          "Processor",
                                                                                          "Storage.Capacity",
                                                                                          "RAM"))

comp_analytical_amce_diff <- comp_analytical_amce_diff %>% filter(feature=="Warranty" |
                                                                    feature=="Liability" |
                                                                    feature=="Conflict.Resolution" |
                                                                    feature=="Privacy")

comp_analytical <- plot(rbind(comp_analytical_amce, comp_analytical_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.25, 0.25) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 8))+
  labs(x = "AMCEs", 
       y = "", 
       title = "A. Computers") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9)) +
  facet_grid(feature ~ BY, 
             scales = "free")

comp_analytical

### Figure S11 in the supplementary material

ggsave("figures/Figure_S11.jpg",
       height = 8,
       width = 12,
       dpi = 500,
       scale = 0.7)

# Analytical group analysis: laundry machines

laundry_analytical_amce <- cj(laundry_ind, selected ~ 
                                Brand +
                                Conflict.Resolution +
                                Liability +
                                Privacy +
                                Price +
                                Depth +
                                Noise +
                                Warranty +
                                Load.Capacity, 
                              id = ~Response.ID, 
                              estimate = "amce", 
                              by = ~analytical_thinking_dummy)

laundry_analytical_amce_diff <- cj(laundry_ind, selected ~ 
                                     Brand +
                                     Conflict.Resolution +
                                     Liability +
                                     Privacy +
                                     Price +
                                     Depth +
                                     Noise +
                                     Warranty +
                                     Load.Capacity, 
                                   id = ~Response.ID, 
                                   estimate = "amce_diff", 
                                   by = ~analytical_thinking_dummy)

laundry_analytical_amce$feature <- factor(laundry_analytical_amce$feature, levels = c("Warranty",
                                                                                      "Liability",
                                                                                      "Conflict.Resolution",
                                                                                      "Privacy",
                                                                                      "Brand",
                                                                                      "Price",
                                                                                      "Depth",
                                                                                      "Load.Capacity",
                                                                                      "Noise"))

laundry_analytical_amce <- laundry_analytical_amce %>% filter(feature=="Warranty" |
                                                                feature=="Liability" |
                                                                feature=="Conflict.Resolution" |
                                                                feature=="Privacy")

laundry_analytical_amce_diff$feature <- factor(laundry_analytical_amce_diff$feature, levels = c("Warranty",
                                                                                                "Liability",
                                                                                                "Conflict.Resolution",
                                                                                                "Privacy",
                                                                                                "Brand",
                                                                                                "Price",
                                                                                                "Depth",
                                                                                                "Load.Capacity",
                                                                                                "Noise"))

laundry_analytical_amce_diff <- laundry_analytical_amce_diff %>% filter(feature=="Warranty" |
                                                                          feature=="Liability" |
                                                                          feature=="Conflict.Resolution" |
                                                                          feature=="Privacy")

laundry_analytical <- plot(rbind(laundry_analytical_amce, laundry_analytical_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.30, 0.30) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 8))+
  labs(x = "AMCEs", 
       y = "", 
       title = "B. Laundry machines") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9)) +
  facet_grid(feature ~ BY, 
             scales = "free")

laundry_analytical

#### Figure S12 in the supplementary material

ggsave("figures/Figure_S12.jpg",
       height = 8,
       width = 12,
       dpi = 500,
       scale = 0.7)

## Trust in brand

### Trust: computers

comp_trust_amce <- cj(comp_ind, selected ~ 
                        Conflict.Resolution +
                        Liability +
                        Privacy +
                        Price +
                        Processor +
                        Storage.Capacity +
                        Warranty +
                        RAM, 
                      id = ~Response.ID, 
                      estimate = "amce", 
                      by = ~trust_dummy)

comp_trust_amce_diff <- cj(comp_ind, selected ~ 
                             Brand +
                             Conflict.Resolution +
                             Liability +
                             Privacy +
                             Price +
                             Processor +
                             Storage.Capacity +
                             Warranty +
                             RAM, 
                           id = ~Response.ID, 
                           estimate = "amce_diff", 
                           by = ~trust_dummy)

comp_trust_amce$feature <- factor(comp_trust_amce$feature, levels = c("Warranty",
                                                                      "Liability",
                                                                      "Conflict.Resolution",
                                                                      "Privacy",
                                                                      "Brand",
                                                                      "Price",
                                                                      "Processor",
                                                                      "Storage.Capacity",
                                                                      "RAM"))

comp_trust_amce <- comp_trust_amce %>% filter(feature=="Warranty" |
                                                feature=="Liability" |
                                                feature=="Conflict.Resolution" |
                                                feature=="Privacy")

comp_trust_amce_diff$feature <- factor(comp_trust_amce_diff$feature, levels = c("Warranty",
                                                                                "Liability",
                                                                                "Conflict.Resolution",
                                                                                "Privacy",
                                                                                "Brand",
                                                                                "Price",
                                                                                "Processor",
                                                                                "Storage.Capacity",
                                                                                "RAM"))

comp_trust_amce_diff <- comp_trust_amce_diff %>% filter(feature=="Warranty" |
                                                          feature=="Liability" |
                                                          feature=="Conflict.Resolution" |
                                                          feature=="Privacy")

comp_trust <- plot(rbind(comp_trust_amce, comp_trust_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.25, 0.25) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 8))+
  labs(x = "AMCEs", 
       y = "", 
       title = "A. Computers") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9)) +
  facet_grid(feature ~ BY, 
             scales = "free")

comp_trust

### Figure S1 in the supplementary material

ggsave("figures/Figure_S1.jpg",
       height = 8,
       width = 12,
       dpi = 500,
       scale = 0.7)
 
### Trust: laundry machines

laundry_trust_amce <- cj(laundry_ind, selected ~ 
                           Conflict.Resolution +
                           Liability +
                           Privacy +
                           Price +
                           Depth +
                           Load.Capacity +
                           Warranty +
                           Noise, 
                         id = ~Response.ID, 
                         estimate = "amce", 
                         by = ~trust_dummy)

laundry_trust_amce_diff <- cj(laundry_ind, selected ~ 
                                Brand +
                                Conflict.Resolution +
                                Liability +
                                Privacy +
                                Price +
                                Depth +
                                Load.Capacity +
                                Warranty +
                                Noise, 
                              id = ~Response.ID, 
                              estimate = "amce_diff", 
                              by = ~trust_dummy)

laundry_trust_amce$feature <- factor(laundry_trust_amce$feature, levels = c("Warranty",
                                                                            "Liability",
                                                                            "Conflict.Resolution",
                                                                            "Privacy",
                                                                            "Brand",
                                                                            "Price",
                                                                            "Depth",
                                                                            "Load.Capacity",
                                                                            "Noise"))

laundry_trust_amce <- laundry_trust_amce %>% filter(feature=="Warranty" |
                                                      feature=="Liability" |
                                                      feature=="Conflict.Resolution" |
                                                      feature=="Privacy")

laundry_trust_amce_diff$feature <- factor(laundry_trust_amce_diff$feature, levels = c("Warranty",
                                                                                      "Liability",
                                                                                      "Conflict.Resolution",
                                                                                      "Privacy",
                                                                                      "Brand",
                                                                                      "Price",
                                                                                      "Depth",
                                                                                      "Load.Capacity",
                                                                                      "Noise"))

laundry_trust_amce_diff <- laundry_trust_amce_diff %>% filter(feature=="Warranty" |
                                                                feature=="Liability" |
                                                                feature=="Conflict.Resolution" |
                                                                feature=="Privacy")

laundry_trust <- plot(rbind(laundry_trust_amce, laundry_trust_amce_diff), size = 2, feature_headers = FALSE, color = c("black", "red", "black")) + 
  ggplot2::facet_wrap(~BY, ncol = 3L) +
  xlim(-0.30, 0.3) +
  theme(legend.position = "none",
        plot.title = element_text(hjust = 0.5, size = 12, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_rect(colour="black",
                                        fill="white"),
        axis.text.x = element_text(size = 7),
        strip.text = element_text(
          size = 8))+
  labs(x = "AMCEs", 
       y = "", 
       title = "B. Laundry machines") +
  geom_vline(xintercept = 0.0, color = "gray") +
  scale_color_manual(values = rep("black", 9)) +
  facet_grid(feature ~ BY, 
             scales = "free")

laundry_trust

#### Figure S2 in the supplementary material

ggsave("figures/Figure_S2.jpg",
       height = 8,
       width = 12,
       dpi = 500,
       scale = 0.7)

# Manipulations

manipulations <- readRDS("manipulation_checks.RDS")

## Warranty

ggplot(manipulations) +
  geom_density(aes(x = warranty_no), color = "maroon", alpha = 0.5, fill = "maroon", adjust = 3) +
  geom_density(aes(x = warranty_2_year), color = "orange", alpha = 0.5, fill = "orange", adjust = 3) +
  geom_density(aes(x = warranty_10_year), color = "darkgreen", alpha = 0.5, fill = "darkgreen", adjust = 3) +
  theme_classic() +
  labs(x = "Perceived benefits to consumers", y = "Density") +
  annotate("text", x = 5.7, y = 0.5, label = "10 year warranty", size = 3) +
  annotate("text", x = 5, y = 0.25, label = "2 year warranty", size = 3) +
  annotate("text", x = 1.5, y = 0.22, label = "No warranty", size = 3)

ggsave("figures/Figure_2_Panel_D.jpg",
       height = 5,
       width = 10,
       dpi = 500,
       scale = 0.7)

t.test(manipulations$warranty_no, 
       manipulations$warranty_2_year)

t.test(manipulations$warranty_10_year, 
       manipulations$warranty_2_year)

## Privacy

ggplot(manipulations) +
  geom_density(aes(x = privacy_marketing), color = "maroon", alpha = 0.5, fill = "maroon", adjust = 2) +
  geom_density(aes(x = privacy_no), color = "orange", alpha = 0.5, fill = "orange", adjust = 2) +
  geom_density(aes(x = privacy_development), color = "yellow", alpha = 0.5, fill = "yellow", adjust = 2) +
  geom_density(aes(x = privacy_full), color = "darkgreen", alpha = 0.5, fill = "darkgreen", adjust = 2) +
  theme_classic() +
  labs(x = "Perceived benefits to consumers", y = "Density") +
  annotate("text", x = 5.7, y = 0.3, label = "Full privacy", size = 3) +
  annotate("text", x = 4.5, y = 0.24, label = "No privacy development", size = 3) +
  annotate("text", x = 2.5, y = 0.25, label = "No privacy", size = 3) +
  annotate("text", x = 1.6, y = 0.19, label = "No privacy: marketing", size = 3) +
  geom_segment(aes(x=2.5, y=0.23, xend=3.1, yend=0.17), arrow = arrow(length=unit(.1, 'cm')))

ggsave("figures/Figure_2_Panel_B.jpg",
       height = 5,
       width = 10,
       dpi = 500,
       scale = 0.7)

t.test(manipulations$privacy_marketing, 
       manipulations$privacy_no)

t.test(manipulations$privacy_development, 
       manipulations$privacy_no)

t.test(manipulations$privacy_development, 
       manipulations$privacy_full)

## Liability

ggplot(manipulations) +
  geom_density(aes(x = liability_consumer), color = "maroon", alpha = 0.5, fill = "maroon", adjust = 2) +
  geom_density(aes(x = liability_both), color = "orange", alpha = 0.5, fill = "orange", adjust = 2) +
  geom_density(aes(x = liability_seller), color = "darkgreen", alpha = 0.5, fill = "darkgreen", adjust = 2) +
  theme_classic() +
  labs(x = "Perceived benefits to consumers", y = "Density") +
  annotate("text", x = 5.9, y = 0.28, label = "Liability seller", size = 3) +
  annotate("text", x = 4, y = 0.28, label = "Liability both", size = 3) +
  annotate("text", x = 1.5, y = 0.22, label = "Liability consumer", size = 3)

ggsave("figures/Figure_2_Panel_C.jpg",
       height = 5,
       width = 10,
       dpi = 500,
       scale = 0.7)

t.test(manipulations$liability_consumer, 
       manipulations$liability_both)

t.test(manipulations$liability_seller, 
       manipulations$liability_both)

## Conflict resolution

ggplot(manipulations) +
  geom_density(aes(x = conflict_resolution_seller), color = "maroon", alpha = 0.5, fill = "maroon", adjust = 2) +
  geom_density(aes(x = conflict_resolution_consumer), color = "darkgreen", alpha = 0.5, fill = "darkgreen", adjust = 2) +
  theme_classic() +
  labs(x = "Perceived benefits to consumers", y = "Density") +
  annotate("text", x = 4.7, y = 0.26, label = "Conflict resolution: consumer choice", size = 3) +
  annotate("text", x = 1.9, y = 0.16, label = "Conflict resolution: seller choice", size = 3)

ggsave("figures/Figure_2_Panel_A.jpg",
       height = 5,
       width = 10,
       dpi = 500,
       scale = 0.7)

t.test(manipulations$conflict_resolution_seller, 
       manipulations$conflict_resolution_consumer)

######## END ######## END ######## END ########

